package org.example.campus_sys_backend.controller;


import org.example.campus_sys_backend.model.ClassInfo;
import org.example.campus_sys_backend.service.ClassService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;

@RestController
@RequestMapping("/class")
public class ClassController {
    @Autowired
    public ClassService classService;
    @RequestMapping("/add")
    public Boolean addClass(ClassInfo classInfo){
        if (classInfo != null){
            classService.insertClass(classInfo);
            return true;
        }
        System.out.println("参数输入不合法");
        return false;

    }
    @RequestMapping("/cfg")
    public Boolean cfgClass(Integer classId, String teacherName){
        if (classId > 0 || teacherName != null){
            classService.configureTeacher(classId, teacherName);
            return true;
        }
        return false;
    }
    @RequestMapping("/update")
    public Boolean updClass(Integer id, String name, @DateTimeFormat(pattern = "yyyy-MM-dd") Date createdTime, String classDesc, Integer activityId){
        if(id > 0){
            classService.updateClass(id,name,createdTime,classDesc,activityId);
            return true;
        }
        return false;
    }
}
